package com.songxh.facade.controller;

import com.songxh.application.api.LoginService;
import com.songxh.application.dto.LoginInfoDTO;
import com.songxh.application.dto.UserLoginParamsDTO;
import com.songxh.core.base.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录相关接口
 * @author songxh
 * @create 2022-12-20-20:03
 */
@RestController
@RequestMapping("/gra/songxh/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 根据账号登录
     * @param userLoginParamsDTO 账号和密码
     * @return
     */
    @PostMapping("/loginByAccount")
    public CommonResult<LoginInfoDTO> loginByAccount(@RequestBody UserLoginParamsDTO userLoginParamsDTO){
        LoginInfoDTO loginByAccount = loginService.loginByAccount(userLoginParamsDTO);
        return CommonResult.success(loginByAccount);
    }

    @PostMapping("/logout")
    public CommonResult<Boolean> logout(){
        Boolean logout = loginService.logout();
        return CommonResult.success(logout);
    }

}
